package com.sse.product.controller.rbac;

import com.sse.product.common.ResultCode;
import com.sse.product.rbac.entity.User;
import com.sse.product.model.rbac.ResponseVo;
import com.sse.product.rbac.service.ILoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class LoginController {

    @Autowired
    private ILoginService loginService;



    @GetMapping("/hello")
    @PreAuthorize("hasAuthority('admin')")
    public String hello(){
        return "sayHi : hello !";
    }

    @PostMapping("/user/login")
    public ResponseVo login(@RequestBody User user){
        return ResponseVo.assemble(ResultCode.SUCCESS, loginService.login(user));
    }

    @RequestMapping("/user/logout")
    public ResponseVo logout(){
        return ResponseVo.assemble(ResultCode.SUCCESS.getCode(), "退出成功，请客户端清空token!", loginService.logout());
    }
}
